<?php
$appLinks = Blyn::app()->getUIManager()->getLinks();
$createSpaceLink = $appLinks['createSpace']['ajaxUrl'];
$apps = Blyn::app()->getActiveSpace()->getApps();
$activeApp = Blyn::app()->getActiveApp();

$items = array();
$item = array();

$displayName = Blyn::app()->getActiveSpace()->getDisplayName();

if (Blyn::app()->getActiveOperation() != NULL) {
    $currentOperation = Blyn::app()->getActiveOperation();
    if ($currentOperation->getId() == Blyn::app()->getCurrentUser()->getPersonalSpace()->
                    getApp('BPersonalApp')->getOperationByName(BPersonalApp::OPERATION_CREATESpace)->getId()) {
        $displayName = "Create your Space";
    }
    if ($currentOperation->getId() == Blyn::app()->getCurrentUser()->getPersonalSpace()->
                    getApp('BPersonalApp')->getOperationByName(BPersonalApp::OPERATION_JOINSpace)->getId()) {
        $displayName = "Space Store";
    }
    if ($currentOperation->getId() == Blyn::app()->getCurrentUser()->getPersonalSpace()->
                    getApp('BPersonalApp')->getOperationByName(BPersonalApp::OPERATION_LISTMYSpaceS)->getId()) {
        $displayName = "My Spaces ";
    }
}

//array_push($items, $item);
foreach ($apps as $app) {

    $name = $app->getName();

    if ($name == 'SpaceEngine') {
        $name = 'Home';
    }

    if ($app->getId() != Blyn::app()->getCurrentUser()->getPersonalSpace()->getApp('BPersonalApp')->getId()) {
        //$item['url'] = $app->getUIManager()->getUrl(array('ajaxLink' => array('name' => $name)));
        $item['url'] = $app->getUIManager()->getAjaxLink($name);
        $item['label'] = $name;
        $item['active'] = '';

        if ($app->getId() == $activeApp->getId())
            $item['active'] = 'active';

        array_push($items, $item);
    }
}
?>
<div id="SpaceTopBar" style="height: 80px">
    <div class="container" style="margin: auto;margin-top: 0px;padding-top: 15px;">
        <div class="row-fluid">
            <div class="span4">
                <h4 style="color: whitesmoke"> <?php echo $displayName; ?></h4>
            </div>
            <div class="span2"></div>
            <div class='span6'>               
                <div class="btn-toolbar" style="margin-top: 5px">
                    <?php echo $createSpaceLink; ?>                            
                </div>               
            </div>
        </div>   
        <div style="height: 25px;background-color: #F5F5F5;margin-top: 10px"></div>
    </div>
      
    <div style="height: 25px;background-color: #F5F5F5;margin-top: 10px"></div>
</div>

